package cn.itlaobing.web.servlet;

import cn.itlaobing.BusinessException.MyBusinessException;
import cn.itlaobing.dao.ItlbFocussDao;
import cn.itlaobing.servise.ItlbGoodServise;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * 类名: cn.itlaobing.web.servlet
 * 功能:
 * 作者:
 * 日期: 2017/11/13 15:55
 */
@WebServlet("/home/index")
public class HomeServlet extends HttpServlet {
    private Logger log= Logger.getLogger(this.getClass());
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ItlbGoodServise igs=new ItlbGoodServise();
        ItlbFocussDao ifd=new ItlbFocussDao();
        //获取热销商品
        List<Map<String, Object>> mapList=null;
        try {
            mapList=igs.QuerySix();
        } catch (MyBusinessException e) {
            mapList=null;
            log.debug(e.getMessage());
        }
        //获取最新上架商品
        List<Map<String,Object>> veryLatest=null;
        try {
            veryLatest=igs.veryLatest();
        } catch (MyBusinessException e) {
            veryLatest=null;
            log.debug(e.getMessage());
        }
        //获取轮播图地址
        List<Object> imgURL=null;
        try {
            imgURL=ifd.gainImgURL();
        } catch (SQLException e) {
            imgURL=null;
            log.debug(e.getMessage());
        }
        req.setAttribute("HOTPRODUCTS",mapList);
        req.setAttribute("IMGURL",imgURL);
        req.setAttribute("VERYLATEST",veryLatest);
        req.getRequestDispatcher("/WEB-INF/views/display/index.jsp").forward(req,resp);
    }
}
